package JUC;

import java.util.concurrent.atomic.AtomicReference;

class User{
    String name;
    int age;

    public User(String n, int a){
        this.name = n;
        this.age = a;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class AtomicReferenceDemo {

    public static void main(String[] args) {
        User z3 = new User("z3", 23);
        User l4 = new User("l4", 25);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(z3);

        System.out.println(atomicReference.compareAndSet(z3, l4) + "\t" +
                atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(z3, l4) + "\t" +
                atomicReference.get().toString());
    }
}
